package com.example.myapplication.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;

import com.example.myapplication.R;

public class activity_privateChat extends AppCompatActivity {

    private EditText mChatInputEditText;

    private Button mSendButton;
    private Button mGroupButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_private_chat);


        // 获取聊天输入框，发送按钮和群聊按钮的引用
        mChatInputEditText = findViewById(R.id.chatInputEditText);
        mSendButton = findViewById(R.id.sendButton);
        mGroupButton = findViewById(R.id.privateButton);

        //设置群聊按钮点击事件监听器
        mGroupButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1=new Intent(activity_privateChat.this,activity_chat.class);
                startActivity(intent1);
            }
        });

        mChatInputEditText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 请求焦点
                mChatInputEditText.setFocusableInTouchMode(true);
                mChatInputEditText.requestFocus();

                // 显示键盘
                InputMethodManager inputMethodManager =
                        (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputMethodManager.showSoftInput(mChatInputEditText, 0);
            }
        });

        // 设置发送按钮的点击事件监听器
        mSendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 获取文本输入框中的消息内容
                String message = mChatInputEditText.getText().toString();

                // 然后在这里处理发送消息的逻辑，例如将消息发送到WebSocket服务器

                // 清空文本输入框
                mChatInputEditText.setText("");
            }
        });
    }
}